package shape2D;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;

// 矩形 
public class RectangleDemo extends Application {
	private Pane root = new Pane();
	private Rectangle r1;
	private Rectangle r2;
	private Rectangle r3;
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		// 普通矩形
		r1 = new Rectangle(25, 20, 100, 70);    // 左上角坐标，宽，高
		r1.setStrokeLineCap(StrokeLineCap.ROUND);
		r1.setStrokeType(StrokeType.CENTERED);		// 设置边框线在中间
		r1.getStrokeDashArray().addAll(15d, 15d);		// 设置虚线边框
		r1.setStrokeWidth(10);
		r1.setStroke(Color.BLACK);      // 设置边界,填充颜色(默认为边框白色,填充黑色)     
		r1.setFill(Color.PINK);
		root.getChildren().addAll(r1);   
		
		// 圆角矩形
		r2 = new Rectangle(25, 150, 100, 70);
		r2.setArcWidth(30);     
		r2.setArcHeight(30);
		root.getChildren().addAll(r2);
		
		for(int i=0; i<4; i++) {
			r3 = new Rectangle(200, 50, 100, 30);
			r3.setRotate(i*360/8);                 
			r3.setStroke(Color.color(Math.random(), Math.random(), Math.random())); // 随机颜色
			r3.setFill(Color.WHITE);     // 若为setfill(null)则无颜色填充，即透明
			root.getChildren().add(r3);
		}
		
		Scene scene = new Scene(root, 400, 300);
		stage.setScene(scene);
		stage.setTitle("Rectangle");
		stage.show();
	}
}




